package com.sunyard.manage.config;

import feign.Client;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class Config {

    @Bean
    public Client feignClient(SpringClientFactory clientFactory) {
        CachingSpringLoadBalancerFactory bean = cachingSpringLoadBalancerFactory(clientFactory);
        return new LoadBalancerFeignClient(new InFeignClient(null, null), bean, clientFactory);
    }

    public CachingSpringLoadBalancerFactory cachingSpringLoadBalancerFactory(SpringClientFactory factory) {
        return new CachingSpringLoadBalancerFactory(factory);
    }

}
